package org.cupk2.tools.web;

import org.cupk2.tools.i18n.I18n;
import org.cupk2.tools.json.CupkJsons;

public class CupkResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;
    private String version="cupk2";

    public static CupkResponseResult getInstance(CupkResponseCode cupkResponseCode, String msg, Object data) {
        return new CupkResponseResult(cupkResponseCode, msg, data);
    }

    public static CupkResponseResult getInstance(CupkResponseCode cupkResponseCode, String msg) {
        return new CupkResponseResult(cupkResponseCode, msg);
    }

    public static CupkResponseResult getInstance(CupkResponseCode cupkResponseCode, Object data) {
        return new CupkResponseResult(cupkResponseCode, data);
    }

    public static CupkResponseResult getInstance(CupkResponseCode cupkResponseCode) {
        return new CupkResponseResult(cupkResponseCode);
    }

    public CupkResponseResult(CupkResponseCode cupkResponseCode, String msg, T data) {
        this.code = cupkResponseCode.getCode();
        this.msg = msg;
        this.data = data;
    }

    public CupkResponseResult(CupkResponseCode cupkResponseCode, String msg) {
        this.code = cupkResponseCode.getCode();
        this.msg = I18n.msg(msg);
    }

    public CupkResponseResult(CupkResponseCode cupkResponseCode) {
        this.code = cupkResponseCode.getCode();
        this.msg = cupkResponseCode.getTitle();
    }

    public CupkResponseResult(CupkResponseCode cupkResponseCode, T data) {
        this.code = cupkResponseCode.getCode();
        this.msg = cupkResponseCode.getTitle();
        this.data = data;
    }

    public String getVersion() {
        return version;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public String toJson() {
        return CupkJsons.toFormatJson(this);
    }
}
